home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / c / rel_aix.c < prev    next >
C/C++ Source or Header  |  1990-01-07  |  3KB  |  111 lines

  1.  
  2. /* Copyright William Schelter. All rights reserved.  This file does
  3. the low level relocation which tends to be very system dependent.
  4. It is included by the file sfasl.c
  5. */
  6.  
  7. #define EXTERNAL_P(rel) \
  8.   relocation_info.r_type & )
  9.   
  10. #define HI12 0xfff00000
  11. #define LO20 ~HI12
  12.     
  13. foo(){};
  14. relocate()
  15. {
  16.   char *where;
  17.  
  18.   {unsigned int new_value;
  19.    char tem [10];
  20. #ifdef DEBUG
  21.    printf("\nEnter relocate:*srelocation_info {r_symndx= %d, r_vaddr = %d,:",
  22.       relocation_info.r_symndx,
  23.       relocation_info.r_vaddr              
  24.       );fflush(stdout);
  25. #endif
  26.    where = the_start + relocation_info.r_vaddr;
  27.  
  28.    if(relocation_info.r_symndx < S_BSS){
  29. #ifdef DEBUG
  30.      printf("(relocation_info.r_symndx = %d < S_BSS)",relocation_info.r_symndx
  31.         );fflush(stdout);
  32.      print_name(&symbol_table[relocation_info.r_symndx]);
  33. #endif     
  34.      switch(relocation_info.r_type){
  35.      case R_KCALL:
  36.        /* instructions like balix take a 20 bit argument
  37.       which wants to be the displacement in half words to
  38.       from the address of the instruction to the actual
  39.       address. */
  40.        {int displ;
  41.     unsigned int new;
  42.     displ=  symbol_table[relocation_info.r_symndx].n_value -
  43.       (int)where;
  44.     new= *(unsigned int *)where;
  45.  
  46.     /*            *(unsigned int *)where
  47.                 = (new & HI12) | ((displ >> 1) & LO20); */
  48.       /* need to store the halves separately, because word pointers
  49.          must be aligned */
  50.     ((unsigned short *)where)[0]=0x8b00;
  51.     ((unsigned short *)where)[1]=0x0c00;
  52.     return ;}
  53.      case R_PCRBYTE:        /* byte (pc relative) */
  54.      case R_PCRWORD:        /* word (pc relative) */
  55.      case R_PCRLONG:        /* word (pc relative) */       
  56.        new_value=   - (int)start_address
  57.      + symbol_table[relocation_info.r_symndx].n_value;
  58.        break;
  59.      default:
  60.        { new_value= 
  61.        symbol_table[relocation_info.r_symndx].n_value;}}}
  62.    else
  63.      { switch(relocation_info.r_symndx){
  64.      case S_DATA: case S_BSS: case S_TEXT:
  65.        new_value= (int)start_address;
  66.        break;
  67.      default:
  68.        dprintf(relocation_info.r_type = %d, relocation_info.r_type);
  69. #ifdef DEBUG       
  70.        printf("\nrelocation_info {r_symndx= %d, r_vaddr = %d, Ignored:",
  71.           relocation_info.r_symndx,
  72.           relocation_info.r_vaddr              
  73.           );fflush(stdout);
  74. #endif
  75.        goto DONT;}
  76.      };
  77.    dprintf((type %d),relocation_info.r_type);
  78.    switch(relocation_info.r_type){
  79.    case R_RELBYTE:
  80.    case R_PCRBYTE:     
  81.      *( char *)where = new_value + *( char *) where;
  82.      break;
  83.    case R_RELWORD:
  84.    case R_PCRWORD:     
  85.      *( short *)where = new_value + *( short *) where;
  86.      break;
  87.    case R_RELLONG:
  88.    case R_PCRLONG:
  89.      /* I guess it must be long if in these areas
  90.     I don't see how the size can vary.
  91.       */
  92.       if (((int)where %4) !=0) FEerror("long alignment not long aligned",0,0);
  93.      *( long *)where = new_value + *( long *) where;
  94.      break;
  95.    default:
  96.      printf("(bad type %d)",relocation_info.r_type);
  97.    }
  98.  DONT:;
  99.  }
  100. }
  101.  
  102. typedef int (*FUNC)();
  103.  
  104.  
  105. /*  #define describe_sym(n) do{if (debug){printf("Sym No %d:",n); print_name(symbol_table+ (n));}}while(0)
  106. */
  107.  
  108. /* #include "spadutils.c" */
  109.  
  110.  
  111.